//
//  Continent.m
//  Risiko
//
//  Created by Murgia Giovanni on 06/07/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Continent.h"


@implementation Continent
-(id) initWithName:(NSString*) newName{
	[super init];
	name=newName;
	countries = [[NSMutableSet alloc] init];
	return self;
}
-(NSString*) getName{
	return name;
}
-(void) addCountry:(Country*) toAdd{
	[countries addObject:[toAdd getName]];
}
-(Boolean) hasThisCountry:(Country*) aCountry{
	return [countries containsObject:[aCountry getName]];
}
- (void) encodeWithCoder:(NSCoder*) coder
{
	[coder encodeObject:name forKey:@"name"];
	[coder encodeObject:countries forKey:@"countries"];
}


- (id) initWithCoder:(NSCoder*) coder
{	
	[self initWithName:[coder decodeObjectForKey:@"name"]];
	countries = [coder decodeObjectForKey:@"countries"];
	return self;
}
-(Boolean) containsAll: (NSSet*) someCountries{ // returns true if the set contains all the continent
	int cont = 0;
	for (Country * k in someCountries)
		if ([self hasThisCountry:k])
			cont++;
	return cont==[countries count];
}
@end
